<?php

namespace App\Http\Controllers\Platform;

use App\Models\Project;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;

/**
 * 平台端项目逻辑控制器
 *
 * Date: 07/05/2018
 * @author George
 * @package App\Http\Controllers\Platform
 */
class ProjectController extends Controller
{
	/**
	 * 项目数据报表
	 *
	 * Date: 07/05/2018
	 * @author George
	 * @param Request $request
	 * @return \Illuminate\Http\JsonResponse
	 */
	public function report(Request $request)
	{
		$project_name = $request->get('project_name');
		$company_name = $request->get('company_name');
		$paginate = $request->get('paginate', 15);

		$query = DB::table('projects')
			->select(['projects.id', 'projects.name', 'projects.address', 'projects.cover', 'companies.title as company'])
			->join('companies', 'projects.company_id', '=', 'companies.id');

		if ($project_name) {
			$query->where('projects.name', 'like', "%{$project_name}%");
		}

		if ($company_name) {
			$query->where('companies.title', 'like', "%{$company_name}%");
		}

		return success($query->paginate($paginate));
	}

	/**
	 * 获取项目详情
	 *
	 * Date: 07/05/2018
	 * @author George
	 * @param Project $project
	 * @return \Illuminate\Http\JsonResponse
	 */
	public function details(Project $project)
	{
		return success($project);
	}
}
